Fix validation to accept lowercase status code ranges (4xx, 5xx) in OpenAPI responses #2415
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The OpenAPI validation was incorrectly rejecting lowercase status code ranges like "4xx" and "5xx" in response definitions. The regex pattern only accepted uppercase "XX" variants.
Problem
When defining OpenAPI responses with lowercase status code ranges, validation would fail:
Error:
Responses key must be 'default', an HTTP status code, or one of the following strings representing a range of HTTP status codes: '1XX', '2XX', '3XX', '4XX', '5XX'
Solution
^[1-5](?>[0-9]{2}|XX)$
to^[1-5](?>[0-9]{2}|[xX]{2})$
to accept both cases[GeneratedRegex]
attribute for .NET 8+ targets for improved performanceChanges Made
partial
to support GeneratedRegexOpenApiResponsesValidationTests.cs
with test cases for:string.Split
calls in BaseOpenApiReference.cs, OpenApiDocument.cs, and OpenApiWorkspace.csTest Results
All tests pass, confirming the fix works correctly:
Now both formats work seamlessly:
Fixes #2414.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.